home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / gnu / a2_0bEmacs_bin.lha / Emacs-19.25 / etc / wakeup.c < prev   
C/C++ Source or Header  |  1993-05-09  |  791b  |  44 lines

  1. /* Program to produce output at regular intervals.  */
  2.  
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. struct tm *localtime ();
  7.  
  8. main (argc, argv)
  9.      int argc;
  10.      char **argv;
  11. {
  12.   int period = 60;
  13.   long when;
  14.   struct tm *tp;
  15.  
  16.   if (argc > 1)
  17.     period = atoi (argv[1]);
  18.  
  19.   while (1)
  20.     {
  21. #ifdef AMIGA
  22.       if (Write(Output(), "Wake up!\n", 9) != 9) exit(0);
  23.       chkabort();
  24. #define sleep(n) Delay(50 * (n))
  25. #else
  26.       /* Make sure wakeup stops when Emacs goes away.  */
  27.       if (getppid () == 1)
  28.     exit (0);
  29.       printf ("Wake up!\n");
  30.       fflush (stdout);
  31. #endif
  32.       /* If using a period of 60, produce the output when the minute
  33.      changes. */
  34.       if (period == 60)
  35.     {
  36.       time (&when);
  37.       tp = localtime (&when);
  38.       sleep (60 - tp->tm_sec);
  39.     }
  40.       else
  41.     sleep (period);
  42.     }
  43. }
  44.